package com.bw.module_service.view

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Rect
import android.graphics.RectF
import android.util.AttributeSet
import android.view.View
import androidx.core.content.ContextCompat

class CirclePunchCardView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {

    private val outerCirclePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
        color = Color.WHITE
        style = Paint.Style.STROKE
        strokeWidth = 10f // 外环宽度，可调整
    }
    private val innerCirclePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
        color = ContextCompat.getColor(context, android.R.color.holo_blue_light) // 蓝色，也可直接写 Color.parseColor("#4DA6FF")
        style = Paint.Style.FILL
    }
    private val textPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
        color = Color.WHITE
        textSize = 40f // 文字大小，可调整
        textAlign = Paint.Align.CENTER
    }

    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        val centerX = width / 2f
        val centerY = height / 2f
        // 绘制白色外环
        val outerRadius = minOf(width, height) / 2f - 5f // 减去一点避免超出
        canvas.drawCircle(centerX, centerY, outerRadius, outerCirclePaint)
        // 绘制蓝色内环
        val innerRadius = outerRadius - outerCirclePaint.strokeWidth
        canvas.drawCircle(centerX, centerY, innerRadius, innerCirclePaint)
        // 绘制文字
        val text = "下午打卡\n13:30-18:00"
        val textBounds = Rect()
        textPaint.getTextBounds(text, 0, text.length, textBounds)
        canvas.drawText(text, centerX, centerY + textBounds.height() / 4, textPaint)
    }
}